Spring Boot/Spring MVC MCQ QUESTIONS AND ANSWER Sample Test,Sample questions

Question:
 How can you access request parameters in a Spring MVC controller method?

1.By using the @RequestParam annotation.

2. By accessing them directly from the HttpServletRequest object.

3.By using the @PathVariable annotation.

4. By using the @RequestHeader annotation.

Posted Date:-2024-01-29 16:15:08


Question:
 How can you define custom database queries in Spring Data JPA?

1.Using XML configuration files.

2.Using SQL scripts executed during application startup.

3.Using the @Query annotation and JPQL or native SQL queries.

4.Using external SQL files loaded at runtime.

Posted Date:-2024-01-29 16:59:44


Question:
 In JPA, which strategy generates a primary key assigned by the database?

1.GenerationType.AUTO

2.GenerationType.SEQUENCE

3.GenerationType.IDENTITY

4.GenerationType.TABLE

Posted Date:-2024-01-29 16:58:19


Question:
 In Spring MVC, what is the role of the ViewResolver?

1.Resolving bean dependencies

2.Handling exceptions

3.Resolving views to specific URLs

4.Handling request parameters

Posted Date:-2024-01-29 16:15:36


Question:
 What does the @ResponseBody annotation do?

1.It sends the return value of a method back to the web response body.

2. It binds the parameters of a method to the request body.

3.It triggers an exception handling method.

4. It binds the result of a method to a view.

Posted Date:-2024-01-29 16:40:21


Question:
 What does the @Valid annotation in Spring MVC do?

1.It ensures that the method is correctly overridden from a superclass.

2. It triggers validation of a method parameter or field.

3. It ensures that an HTTP request is valid.

4.It validates the return type of a method.

Posted Date:-2024-01-29 16:43:14


Question:
 Which annotation is used to autowire a repository into a Spring component?

1.InjectRepository

2.AutoInject

3.Autowire

4.Resource

Posted Date:-2024-01-29 16:51:03


Question:
Choose the correct Query Method:

1.findByFirstNameOrLastName(String firstName, String lastName)

2. findByFirstNameAndLastName(String firstName, String lastName)

3.findByFirstNameOrLastName(Student student)

4.findByFirstNameLastName(String firstName, String lastName)

Posted Date:-2024-01-29 17:00:24


Question:
How can you control transaction management in Spring Data JPA?

1.By using the @Transactional annotation.

2. By configuring the transaction properties in the application.properties file.

3.By extending the JpaTransactionManager class.

4.By adding the @EnableTransactionManagement annotation to the configuration class

Posted Date:-2024-01-29 16:59:19


Question:
How can you customize the column name for a field in a JPA entity?

1.Column(name="custom_name")

2.FieldName("custom_name")

3.TableColumn("custom_name")

4.DatabaseColumn("custom_name")

Posted Date:-2024-01-29 16:54:53


Question:
How can you define a derived query in Spring Data JPA?

1.By annotating a method with @Query

2. By creating a method in the repository with a specific naming convention

3. By using the @DerivedQuery annotation

4.By creating an XML configuration

Posted Date:-2024-01-29 16:50:14


Question:
How can you handle exceptions in Spring MVC?

1.@ExceptionHandler

2.@CatchException

3.@ErrorResolver

4.@ResolveError

Posted Date:-2024-01-29 16:13:40


Question:
How can you indicate a Many-To-One relationship in JPA?

1.ManyToOne

2.OneToMany

3.ManyToMany

4.OneToOne

Posted Date:-2024-01-29 16:56:24


Question:
How can you mark a field as the primary key in a JPA entity?

1.PrimaryKey

2.EntityKey

3.Id

4.Key

Posted Date:-2024-01-29 16:53:21


Question:
How can you perform pagination in Spring Data JPA?

1.Using the @Pageable annotation

2.Using the Page and Pageable interfaces

3.Using the @Pagination annotation

4.Using the Paginator class

Posted Date:-2024-01-29 16:57:43


Question:
How do you execute a native query in Spring Data JPA?

1.Native

2.SQL

3.Execute

4.Query(nativeQuery = true)

Posted Date:-2024-01-29 16:52:24


Question:
How do you redirect to another URL in Spring MVC?

1."redirect:/url_path"

2."forward:/url_path"

3.goto:/url_path"

4.move:/url_path"

Posted Date:-2024-01-29 16:40:48


Question:
How do you specify that a controller method should produce JSON as a response?

1. @Produces("application/json")

2.@ResponseBody(type="json")

3.@ResponseFormat("JSON")

4.@RequestMapping(produces="application/json")

Posted Date:-2024-01-29 16:41:46


Question:
In a Spring Data JPA repository, how can you indicate a method should delete by a specific field?

1.deleteByFieldName

2.removeByFieldName

3.eraseByFieldName

4.exterminateByFieldName

Posted Date:-2024-01-29 16:56:48


Question:
In which layer is Spring MVC used?

1.Data layer

2.Business layer

3.Presentation layer

4.Integration layer

Posted Date:-2024-01-29 16:44:43


Question:
What does MVC stand for in Spring MVC?

1.Multi-View Controller

2.Module-View-Controller

3.Model-View-Controller

4.Model-Value-Configuration

Posted Date:-2024-01-29 16:11:17


Question:
What is Spring MVC

1.A programming language for web development.

2. A lightweight Java framework for building web applications.

3.A database management system for web applications.

4.A library for handling server-side rendering.

Posted Date:-2024-01-29 16:11:51


Question:
What is the aim of Spring Data JPA?

1.Spring Data JPA aims to reduce the amount of boilerplate code required for common database operations.

2.Spring Data JPA aims to provide the implementation for JPA interfaces

3.Spring Data JPA is a JPA provider and implementation for JPA interfaces

4.Spring Data JPA is an ORM framework that provides an implementation for JPA interfaces

Posted Date:-2024-01-29 16:47:06


Question:
What is the default implementation class of the JpaRepository interface?

1.JpaRepositoryImpl class

2.SimpleJpaRepository class

3.DeafultJpaRepository class

4.SimpleCrudRepository class

Posted Date:-2024-01-29 16:49:44


Question:
What is the purpose of the @GeneratedValue annotation in Spring Data JPA?

1.To specify the table name for entity mapping.

2.To define the primary key column in an entity.

3.To configure the fetching strategy for related entities.

4.To automatically generate primary key values for entities.

Posted Date:-2024-01-29 16:53:51


Question:
What is the purpose of the ModelAndView object in Spring MVC?

1.To store and pass data between the controller and the view.

2.To define the layout and styling of the web application.

3.To handle user authentication and authorization.

4.To manage the application's data access layer.

Posted Date:-2024-01-29 16:14:09


Question:
Which annotation binds a method parameter to a named attribute?

1.@ModelAttribute

2.@ParameterAttribute

3.@BindAttribute

4.@RequestValue

Posted Date:-2024-01-29 16:13:08


Question:
Which annotation in JPA allows you to embed another object as part of your entity?

1.Embeddable

2.Embedded

3.Include

4.PartOf

Posted Date:-2024-01-29 16:58:44


Question:
Which annotation in JPA allows you to embed another object as part of your entity?

1.Embeddable

2.Embedded

3.Include

4.PartOf

Posted Date:-2024-01-29 16:58:47


Question:
Which annotation indicates a method should handle HTTP POST requests?

1.@HttpPost

2.@PostHandler

3.@RequestMapping(method = RequestMethod.POST)

4.@PostMapping

Posted Date:-2024-01-29 16:39:32


Question:
Which annotation is commonly used to mark a repository interface in Spring Data JPA?

1.Service

2.Component

3.Controller

4.Repository

Posted Date:-2024-01-29 16:50:34


Question:
Which annotation is used to bind a method parameter to a web request header?

1.@RequestHeader

2.@Header

3.@BindHeader

4.@HTTPHeader

Posted Date:-2024-01-29 16:14:34


Question:
Which annotation is used to create a Named JPQL query?

1.NamedQuery

2.NamedJPQLQuery

3.NamedNativeQuery

4.SQLQuery

Posted Date:-2024-01-29 16:56:04


Question:
Which annotation is used to create a Spring MVC controller class?

1.@ControllerBean

2.@SpringController

3.@WebController

4.@Controller

Posted Date:-2024-01-29 16:12:14


Question:
Which annotation is used to denote a regular expression in URI template in Spring MVC?

1.@Regex

2.@PathVariable

3.@URIExpression

4.@MatchPattern

Posted Date:-2024-01-29 16:38:43


Question:
Which annotation is used to specify a custom query in Spring Data JPA?

1.CustomQuery

2.JPAQuery

3.Query

4.ExecuteQuery

Posted Date:-2024-01-29 16:55:36


Question:
Which annotation marks a class as an entity in JPA?

1.EntityClass

2.JPAEntity

3.Entity

4.TableEntity

Posted Date:-2024-01-29 16:48:48


Question:
Which dependency is required to use Spring Data JPA in a Spring Boot application?

1.spring-boot-starter-data-jpa

2.spring-boot-starter-web

3.spring-boot-starter-test

4.spring-boot-starter-security

Posted Date:-2024-01-29 16:47:34


Question:
Which interface do we extend to create a repository in Spring Data JPA?

1.Repository

2.JpaRepository

3.JpaRepository

4.SpringRepository

Posted Date:-2024-01-29 16:49:16


Question:
Which is the default JPA provider the Spring Data JPA internally uses?

1.EclipseLink

2.MyBatis

3.TopLink

4.Hibernate

Posted Date:-2024-01-29 16:48:08


Question:
Which of the following annotations is used to handle multipart file uploads?

1.@FileUpload

2.@MultipartFile

3.@RequestFile

4.@UploadPart

Posted Date:-2024-01-29 16:41:15


Question:
Which of the following components decides which controller method is to be called for a request?

1.DispatcherServlet

2.Controller

3.HandlerMapping

4.ViewResolver

Posted Date:-2024-01-29 16:42:45


Question:
Which of the following denotes a derived delete query in Spring Data JPA?

1.deleteByFieldName

2.findByFieldName

3.queryByFieldName

4.readByFieldName

Posted Date:-2024-01-29 16:57:08


Question:
Which of the following handles the HTTP request in Spring MVC?

1.DispatcherServlet

2.HandlerInterceptor

3.HttpListener

4.RequestHandler

Posted Date:-2024-01-29 16:12:39


Question:
Which of the following is NOT a fetch type in JPA?

1.EAGER

2.LAZY

3.IMMEDIATE

4.BOTH

Posted Date:-2024-01-29 16:51:21


Question:
Which of the following is NOT a valid Cascade type in JPA?C

1.PERSIST

2.REMOVE

3.MERGE

4.UPDATE

Posted Date:-2024-01-29 16:52:53


Question:
Which of the following represents a form-backing bean in Spring MVC?

1.@FormEntity

2.@ModelEntity

3.@ModelAttribute

4.@BeanForm

Posted Date:-2024-01-29 16:42:15


Question:
Which Spring annotation is used to handle Cross-Origin Resource Sharing (CORS) in Spring MVC?

1.CrossOrigin

2.CORSHandler

3.EnableCORS

4.CORSConfig

Posted Date:-2024-01-29 16:43:41


Question:
Which Spring Boot Starter would you use for developing web applications?

1.spring-boot-starter-web

2. spring-boot-starter-jdbc

3.spring-boot-starter-data

4. spring-boot-starter-app

Posted Date:-2024-01-29 16:44:15


Question:
Which Spring MVC module provides integration with RESTful services?

1.Spring RestController

2. Spring REST

3.Spring Web MVC

4. Spring WebFlux

Posted Date:-2024-01-29 16:39:08


More MCQS

  1. Spring Boot Common Test
  2. Spring Boot - Bootstrapping
  3. Spring Boot - Logging
  4. Spring Boot - Application Properties
  5. Spring Boot - RESTful Web Services
  6. Spring Boot - Exception Handling
  7. Spring Boot - Interceptor
  8. Spring Boot - File Handling
  9. Spring Boot - CORS
  10. Spring Boot - Internationalization
  11. Spring Boot - Scheduling
  12. Spring MCQs
  13. SPRING BOOT MCQ QUESTIONS
  14. Spring MVC MCQ QUESTIONS AND ANSWER
  15. Spring Cloud MCQ QUESTIONS AND ANSWER
  16. Spring WebFlux MCQ OUESTIONS AND ANSWER
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!